
package com.yanfan.parking;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.ibms.common.utils.HttpUtil;
import com.yanfan.ibms.common.utils.HttpUtils2;
import com.yanfan.parking.domain.IbmsParkingPlace;
import com.yanfan.parking.domain.IbmsParkingRecords;
import com.yanfan.parking.mapper.IbmsParkingPlaceMapper;
import com.yanfan.parking.mapper.IbmsParkingRecordsMapper;
import com.yanfan.parking.result.R;
import com.yanfan.parking.service.IIbmsParkingPlaceService;
import com.yanfan.parking.service.IIbmsParkingRecordsService;
import com.yanfan.parking.vo.InOutRecordVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

/**
 * 停车场对接api
 */

@RestController
public class ApiParkingController {

    @Resource
    private IbmsParkingRecordsMapper inOutRecordMapper;

    @Autowired
    private IIbmsParkingRecordsService ibmsVehicleInOutRecordService;

    @Autowired
    private IIbmsParkingPlaceService iIbmsParkingPlaceService;
    /**
     * 上传进出记录接口
     */
    @RequestMapping("/AddInOrOutRecords")
    public JSONObject inOutRecord(@RequestBody IbmsParkingRecords ibmsParkingRecords) {
        ibmsVehicleInOutRecordService.save(ibmsParkingRecords);
        JSONObject result = new JSONObject();
        result.put("resCode",0);
        result.put("resMsg","成功");
        return result;
    }
//
//
////    /**
////     * 获取服务器上停车场子系统停车场信息，并将信息添加到本地数据
////     * @param ibmsParkingPlace
////     */
////    public  void parkingAddCarparkDetails(@RequestBody IbmsParkingPlace ibmsParkingPlace){
////        // 发送POST请求
////        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
////        stringObjectHashMap.put("stationNo","59");
////        JSONObject jsonObject = HttpUtils2
////                .sendPostBody("http://10.22.10.249:9988/Parking/Handheld/GetParkingLotInfo",
////                        null, stringObjectHashMap);
////        Object object = jsonObject.get("parkingLotInfo");
////        List<IbmsParkingPlace> list = JSON.parseArray(object.toString(), IbmsParkingPlace.class);
////        //批量更新或新增到数据
////        iIbmsParkingPlaceService.saveOrUpdateBatch(list);
////    }
//
//
//    /**
//     * 趋势统计图
//     *
//     * @return
//     */
//    @ApiOperation("趋势统计图")
//    @GetMapping("/chart")
//    public JSONObject chart() {
//        JSONObject jsonObject = new JSONObject();
//        String time = DateUtils.getDate();
//        //小时进场数据
//        List<InOutRecordVo> inList = inOutRecordMapper.selectByChartIn(time);
//        //小时出场数据
//        List<InOutRecordVo> outList = inOutRecordMapper.selectByChartOut(time);
//
//        jsonObject.put("inList", inList);
//        jsonObject.put("outList", outList);
//
//        return jsonObject;
//    }
}
